<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="品牌" prop="brands">
        <el-input
          v-model="queryParams.brands"
          placeholder="请输入品牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="累计运行时间(H)" prop="accumulatedRunningTimeHour">
        <el-input
          v-model="queryParams.accumulatedRunningTimeHour"
          placeholder="请输入累计运行时间(H)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品牌总数(品牌)" prop="brandsNumber">
        <el-input
          v-model="queryParams.brandsNumber"
          placeholder="请输入品牌总数(品牌)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="累计保护数据" prop="accumulatedDatas">
        <el-input
          v-model="queryParams.accumulatedDatas"
          placeholder="请输入累计保护数据"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据中心总数(数据中心)" prop="dataCenterNumber">
        <el-input
          v-model="queryParams.dataCenterNumber"
          placeholder="请输入数据中心总数(数据中心)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="正常运行总数(数据中心)" prop="normalDataNumber">
        <el-input
          v-model="queryParams.normalDataNumber"
          placeholder="请输入正常运行总数(数据中心)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="异常运行总数(数据中心)" prop="abnormalDataNumber">
        <el-input
          v-model="queryParams.abnormalDataNumber"
          placeholder="请输入异常运行总数(数据中心)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="正常运行总数(品牌)" prop="normalBrandsNumber">
        <el-input
          v-model="queryParams.normalBrandsNumber"
          placeholder="请输入正常运行总数(品牌)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="异常运行总数(品牌)" prop="abnormalBrandsNumber">
        <el-input
          v-model="queryParams.abnormalBrandsNumber"
          placeholder="请输入异常运行总数(品牌)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="可用容量" prop="availableCapacity">
        <el-input
          v-model="queryParams.availableCapacity"
          placeholder="请输入可用容量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存储总量" prop="totalStorageCapacity">
        <el-input
          v-model="queryParams.totalStorageCapacity"
          placeholder="请输入存储总量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="可用存储个数" prop="availableStorageNumber">
        <el-input
          v-model="queryParams.availableStorageNumber"
          placeholder="请输入可用存储个数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备份时间" prop="backupTime">
        <el-date-picker clearable
          v-model="queryParams.backupTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择备份时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="备份日期" prop="backupDate">
        <el-input
          v-model="queryParams.backupDate"
          placeholder="请输入备份日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="cup使用率" prop="cupUsageRate">
        <el-input
          v-model="queryParams.cupUsageRate"
          placeholder="请输入cup使用率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="内存使用率" prop="memoryUsageRate">
        <el-input
          v-model="queryParams.memoryUsageRate"
          placeholder="请输入内存使用率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日志名称" prop="logName">
        <el-input
          v-model="queryParams.logName"
          placeholder="请输入日志名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="数据中心" prop="dataCenter">
        <el-input
          v-model="queryParams.dataCenter"
          placeholder="请输入数据中心"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备份类型" prop="backupType">
        <el-select v-model="queryParams.backupType" placeholder="请选择备份类型" clearable>
          <el-option
            v-for="dict in dict.type.backup_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="数据量" prop="dataNumber">
        <el-input
          v-model="queryParams.dataNumber"
          placeholder="请输入数据量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据中心百分比" prop="dataCenterPercent">
        <el-input
          v-model="queryParams.dataCenterPercent"
          placeholder="请输入数据中心百分比"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品牌百分比" prop="brandsPercent">
        <el-input
          v-model="queryParams.brandsPercent"
          placeholder="请输入品牌百分比"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备份数据百分比" prop="dataBackupPercent">
        <el-input
          v-model="queryParams.dataBackupPercent"
          placeholder="请输入备份数据百分比"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="累计运行时间(D)" prop="accumulatedRunningTimeDay">
        <el-input
          v-model="queryParams.accumulatedRunningTimeDay"
          placeholder="请输入累计运行时间(D)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:panel:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:panel:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:panel:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:panel:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="panelList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="品牌" align="center" prop="brands">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.brands" :value="scope.row.brands"/>
        </template>
      </el-table-column>
      <el-table-column label="累计运行时间(H)" align="center" prop="accumulatedRunningTimeHour" />
      <el-table-column label="品牌总数(品牌)" align="center" prop="brandsNumber" />
      <el-table-column label="累计保护数据" align="center" prop="accumulatedDatas" />
      <el-table-column label="数据中心总数(数据中心)" align="center" prop="dataCenterNumber" />
      <el-table-column label="正常运行总数(数据中心)" align="center" prop="normalDataNumber" />
      <el-table-column label="异常运行总数(数据中心)" align="center" prop="abnormalDataNumber" />
      <el-table-column label="正常运行总数(品牌)" align="center" prop="normalBrandsNumber" />
      <el-table-column label="异常运行总数(品牌)" align="center" prop="abnormalBrandsNumber" />
      <el-table-column label="可用容量" align="center" prop="availableCapacity" />
      <el-table-column label="存储总量" align="center" prop="totalStorageCapacity" />
      <el-table-column label="可用存储个数" align="center" prop="availableStorageNumber" />
      <el-table-column label="备份时间" align="center" prop="backupTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.backupTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备份日期" align="center" prop="backupDate" />
      <el-table-column label="cup使用率" align="center" prop="cupUsageRate" />
      <el-table-column label="内存使用率" align="center" prop="memoryUsageRate" />
      <el-table-column label="日志名称" align="center" prop="logName" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="数据中心" align="center" prop="dataCenter">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.data_center" :value="scope.row.dataCenter"/>
        </template>
      </el-table-column>
      <el-table-column label="备份类型" align="center" prop="backupType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.backup_type" :value="scope.row.backupType"/>
        </template>
      </el-table-column>
      <el-table-column label="数据量" align="center" prop="dataNumber" />
      <el-table-column label="数据中心百分比" align="center" prop="dataCenterPercent" />
      <el-table-column label="品牌百分比" align="center" prop="brandsPercent" />
      <el-table-column label="备份数据百分比" align="center" prop="dataBackupPercent" />
      <el-table-column label="累计运行时间(D)" align="center" prop="accumulatedRunningTimeDay" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:panel:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:panel:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改仪盘对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="42%" append-to-body>
        <div style="height: 500px;overflow: auto;">
      <el-form ref="form" :inline="true" :model="form" :rules="rules" label-width="130px">
        <el-form-item label="品牌" prop="brands">
          <el-input v-model="form.brands" placeholder="请输入品牌" />
        </el-form-item>
        <el-form-item label="累计运行时间(H)" prop="accumulatedRunningTimeHour">
          <el-input v-model="form.accumulatedRunningTimeHour" placeholder="请输入累计运行时间(H)" />
        </el-form-item>
        <el-form-item label="品牌总数(品牌)" prop="brandsNumber">
          <el-input v-model="form.brandsNumber" placeholder="请输入品牌总数(品牌)" />
        </el-form-item>
        <el-form-item label="累计保护数据" prop="accumulatedDatas">
          <el-input v-model="form.accumulatedDatas" placeholder="请输入累计保护数据" />
        </el-form-item>
        <el-form-item label="数据中心总数(数据中心)" prop="dataCenterNumber">
          <el-input v-model="form.dataCenterNumber" placeholder="请输入数据中心总数(数据中心)" />
        </el-form-item>
        <el-form-item label="正常运行总数(数据中心)" prop="normalDataNumber">
          <el-input v-model="form.normalDataNumber" placeholder="请输入正常运行总数(数据中心)" />
        </el-form-item>
        <el-form-item label="异常运行总数(数据中心)" prop="abnormalDataNumber">
          <el-input v-model="form.abnormalDataNumber" placeholder="请输入异常运行总数(数据中心)" />
        </el-form-item>
        <el-form-item label="正常运行总数(品牌)" prop="normalBrandsNumber">
          <el-input v-model="form.normalBrandsNumber" placeholder="请输入正常运行总数(品牌)" />
        </el-form-item>
        <el-form-item label="异常运行总数(品牌)" prop="abnormalBrandsNumber">
          <el-input v-model="form.abnormalBrandsNumber" placeholder="请输入异常运行总数(品牌)" />
        </el-form-item>
        <el-form-item label="可用容量" prop="availableCapacity">
          <el-input v-model="form.availableCapacity" placeholder="请输入可用容量" />
        </el-form-item>
        <el-form-item label="存储总量" prop="totalStorageCapacity">
          <el-input v-model="form.totalStorageCapacity" placeholder="请输入存储总量" />
        </el-form-item>
        <el-form-item label="可用存储个数" prop="availableStorageNumber">
          <el-input v-model="form.availableStorageNumber" placeholder="请输入可用存储个数" />
        </el-form-item>
        <el-form-item label="备份时间" prop="backupTime">
          <el-date-picker clearable
            v-model="form.backupTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择备份时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备份日期" prop="backupDate">
          <el-input v-model="form.backupDate" placeholder="请输入备份日期" />
        </el-form-item>
        <el-form-item label="cup使用率" prop="cupUsageRate">
          <el-input v-model="form.cupUsageRate" placeholder="请输入cup使用率" />
        </el-form-item>
        <el-form-item label="内存使用率" prop="memoryUsageRate">
          <el-input v-model="form.memoryUsageRate" placeholder="请输入内存使用率" />
        </el-form-item>
        <el-form-item label="日志名称" prop="logName">
          <el-input v-model="form.logName" placeholder="请输入日志名称" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.status"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="数据中心" prop="dataCenter">
          <el-input v-model="form.dataCenter" placeholder="请输入数据中心" />
        </el-form-item>
        <el-form-item label="备份类型" prop="backupType">
          <el-select v-model="form.backupType" placeholder="请选择备份类型">
            <el-option
              v-for="dict in dict.type.backup_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数据量" prop="dataNumber">
          <el-input v-model="form.dataNumber" placeholder="请输入数据量" />
        </el-form-item>
        <el-form-item label="数据中心百分比" prop="dataCenterPercent">
          <el-input v-model="form.dataCenterPercent" placeholder="请输入数据中心百分比" />
        </el-form-item>
        <el-form-item label="品牌百分比" prop="brandsPercent">
          <el-input v-model="form.brandsPercent" placeholder="请输入品牌百分比" />
        </el-form-item>
        <el-form-item label="备份数据百分比" prop="dataBackupPercent">
          <el-input v-model="form.dataBackupPercent" placeholder="请输入备份数据百分比" />
        </el-form-item>
        <el-form-item label="累计运行时间(D)" prop="accumulatedRunningTimeDay">
          <el-input v-model="form.accumulatedRunningTimeDay" placeholder="请输入累计运行时间(D)" />
        </el-form-item>
        <el-form-item label="是否删除，0存在；2删除" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入是否删除，0存在；2删除" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="扩展1" prop="extend1">
          <el-input v-model="form.extend1" placeholder="请输入扩展1" />
        </el-form-item>
        <el-form-item label="扩展2" prop="extend2">
          <el-input v-model="form.extend2" placeholder="请输入扩展2" />
        </el-form-item>
        <el-form-item label="扩展3" prop="extend3">
          <el-input v-model="form.extend3" placeholder="请输入扩展3" />
        </el-form-item>
        <el-form-item label="扩展4" prop="extend4">
          <el-input v-model="form.extend4" placeholder="请输入扩展4" />
        </el-form-item>
        <el-form-item label="扩展5" prop="extend5">
          <el-input v-model="form.extend5" placeholder="请输入扩展5" />
        </el-form-item>
        <el-form-item label="扩展6" prop="extend6">
          <el-input v-model="form.extend6" placeholder="请输入扩展6" />
        </el-form-item>
        <el-form-item label="扩展7" prop="extend7">
          <el-input v-model="form.extend7" placeholder="请输入扩展7" />
        </el-form-item>
        <el-form-item label="扩展8" prop="extend8">
          <el-input v-model="form.extend8" placeholder="请输入扩展8" />
        </el-form-item>
        <el-form-item label="扩展9" prop="extend9">
          <el-input v-model="form.extend9" placeholder="请输入扩展9" />
        </el-form-item>
        <el-form-item label="扩展10" prop="extend10">
          <el-input v-model="form.extend10" placeholder="请输入扩展10" />
        </el-form-item>
      </el-form>
        </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPanel, getPanel, delPanel, addPanel, updatePanel } from "@/api/system/panel";

export default {
  name: "Panel",
  dicts: ['status', 'backup_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 仪盘表格数据
      panelList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        brands: null,
        accumulatedRunningTimeHour: null,
        brandsNumber: null,
        accumulatedDatas: null,
        dataCenterNumber: null,
        normalDataNumber: null,
        abnormalDataNumber: null,
        normalBrandsNumber: null,
        abnormalBrandsNumber: null,
        availableCapacity: null,
        totalStorageCapacity: null,
        availableStorageNumber: null,
        backupTime: null,
        backupDate: null,
        cupUsageRate: null,
        memoryUsageRate: null,
        logName: null,
        status: null,
        dataCenter: null,
        backupType: null,
        dataNumber: null,
        dataCenterPercent: null,
        brandsPercent: null,
        dataBackupPercent: null,
        accumulatedRunningTimeDay: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询仪盘列表 */
    getList() {
      this.loading = true;
      listPanel(this.queryParams).then(response => {
        this.panelList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        brands: null,
        accumulatedRunningTimeHour: null,
        brandsNumber: null,
        accumulatedDatas: null,
        dataCenterNumber: null,
        normalDataNumber: null,
        abnormalDataNumber: null,
        normalBrandsNumber: null,
        abnormalBrandsNumber: null,
        availableCapacity: null,
        totalStorageCapacity: null,
        availableStorageNumber: null,
        backupTime: null,
        backupDate: null,
        cupUsageRate: null,
        memoryUsageRate: null,
        logName: null,
        status: null,
        dataCenter: null,
        backupType: null,
        dataNumber: null,
        dataCenterPercent: null,
        brandsPercent: null,
        dataBackupPercent: null,
        accumulatedRunningTimeDay: null,
        delFlag: null,
        createTime: null,
        createBy: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        extend1: null,
        extend2: null,
        extend3: null,
        extend4: null,
        extend5: null,
        extend6: null,
        extend7: null,
        extend8: null,
        extend9: null,
        extend10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加仪盘";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPanel(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改仪盘";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePanel(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPanel(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除仪盘编号为"' + ids + '"的数据项？').then(function() {
        return delPanel(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/panel/export', {
        ...this.queryParams
      }, `panel_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
